<?php
/**
 * Created by PhpStorm.
 * User: td
 * Date: 15/1/23
 * Time: 上午12:43
 */

namespace Home\Model;
use Think\Model;

class TrustModel extends Model{
    protected $tableName = 'trust';
    protected $pk         = 'id';

    //获取甲方个人主页信任圈子信息
    public function getTrusterInfo($trusted_id){
        $trust_field = array('truster_id');
        $trust_order = '`time` desc';
        $trust_map['trusted_id'] = array('eq',$trusted_id);
        $trust_result = $this->field($trust_field)->order($trust_order)->where($trust_map)->select();
        //dump($trust_result);
        if(is_array($trust_result)){
            foreach($trust_result as &$trust_result_one){
               // 在user表中获取具体信息
                $user_field = array('user_name','image_url');
                $user_map['user_id'] = array('eq',$trust_result_one['truster_id']);
                $user_result = $this->table('User')->field($user_field)->where($user_map)->select();
                if(is_array($user_result)){
                    $trust_result_one['user_name'] = $user_result[0]['user_name'];
                    $trust_result_one['image_url'] = $user_result[0]['image_url'];
                }else{
                    //user表获取信息失败
                }
            }
            return $trust_result;
        }else{
            return 0;
        }

    }
} 